//
//  BaseTableViewController.swift
//  WB
//
//  Created by leador on 17/3/20.
//  Copyright © 2017年 袁满. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    
    var isLogin: Bool = UserAccountViewModel.shareInstance.isLogin
    
    lazy var visitorView:VisitorView = VisitorView.visitorView()
    
    override func loadView() {
        
        isLogin ? super.loadView() : setupVisitorView()
        
    }
    
    
    func setupVisitorView() {
        view = visitorView
        
        visitorView.registerBtn.addTarget(self, action: #selector(BaseTableViewController.regisiterBtnClick), for: .touchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseTableViewController.loginBtnClick), for: .touchUpInside)
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupNavigationItems()
        
    }
    
}

//MARK: ---UI界面---
extension BaseTableViewController {
    
    func setupNavigationItems() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .plain, target: self, action: #selector(BaseTableViewController.regisiterBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .plain, target: self, action: #selector(BaseTableViewController.loginBtnClick))
        
    }
    
}


//MARK: ---事件监听---
extension BaseTableViewController {
    
    func regisiterBtnClick() {
        print("注册")
    }
    
    func loginBtnClick() {
        
        let auto = OauthViewController()
        
        let naAuto = UINavigationController(rootViewController:auto)
        
        present(naAuto, animated: true, completion: nil)
        
    }
    
}



